package ru.gerunn.jdbc.db2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {

	public static void main(String[] args) throws ClassNotFoundException, SQLException {
		Class.forName("com.ibm.db2.jcc.DB2Driver");
		Connection connection = DriverManager.getConnection("jdbc:db2://xxx.xxx.xxx.xxx:xxxxxx/dbname", "user", "password");
		test(connection);
		connection.close();
	}

	public static void test(Connection connection) throws SQLException {
		Statement stmt = connection.createStatement();
		ResultSet rs = stmt.executeQuery("select id from shl.skodalk_users order by id desc");
		while (rs.next()) {
			System.out.println(rs.getInt("id"));
		}
		rs.close();
		stmt.close();
	}

	public static void printSQLException(SQLException e) {
		while (e != null) {
			System.err.println("Error msg: " + e.getMessage());
			System.err.println("SQLSTATE: " + e.getSQLState());
			System.err.println("Error code: " + e.getErrorCode());
			e.printStackTrace();
			// For drivers that support chained exceptions
			e = e.getNextException();
		}
	}

}
